package guis.scene01;

import buslogic.ModelContainer;
import static mymath.Functions._isDouble;
import myutils.MessageHelper;

public class Scene01ViewModel2ModelMapper {

    public void mappeX2(Scene01ViewModel vm, ModelContainer mc, MessageHelper mh) {
        boolean isDoubleX2 = _isDouble(vm.x2.getValue());
        if (isDoubleX2) {
            mc.x2 = new Double(vm.x2.getValue());
            vm.x2.setValue(_getStringValue(mc.x2.toString()));
        } else {
            mh.addMessage("Conversion Error: x2= " + vm.x2.getValue() + " is not a double value!");
        }
    }

    public void mappeX1(Scene01ViewModel vm, ModelContainer mc, MessageHelper mh) {
        boolean isDoubleX1 = _isDouble(vm.x1.getValue());
        if (isDoubleX1) {
            mc.x1 = new Double(vm.x1.getValue());
            vm.x1.setValue(_getStringValue(mc.x1.toString()));
        } else {
            mh.addMessage("Conversion Error: x1= " + vm.x1.getValue() + " is not a double value!");
        }
        /**
         * else { //show old model value --> too strange for the user
         * vm.getVm_x1().setValue(_getStringValue(mc.x1)); }
         */
    }
    
    private String _getStringValue(Object o) {
        String _getStringValue = "";

        if (o != null) {
            _getStringValue = o.toString();
        }

        return _getStringValue;
    }

}
